package ccmis.finance.voucher.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.ejb.Local;
import javax.ejb.Stateless;
import javax.persistence.NamedNativeQueries;
import javax.persistence.NamedNativeQuery;
import javax.persistence.QueryHint;

import ccmis.finance.voucher.entity.Voucher;
import jfox.platform.infrastructure.EntityObject;
import jfox.platform.infrastructure.SuperDAO;
@Stateless
@Local
@NamedNativeQueries(
        {@NamedNativeQuery(
                    name = VoucherDAOBean.GET_VOUCHER_BY_PZID_FLH,
                    query = "SELECT T_V.PZ_ID,T_V.FLH,T_V.FLH,T_V.ZY,T_V.KMDM,T_V.JJE,T_V.DJE,T_V.VSTATUS,T_L.SUBJECT_FULL_NAME AS NAME"+
                    	    " FROM T_FINANCEAL_VOUCHER T_V left join T_FINANCEAL_SUBJECT_LIST T_L "+
                            "    ON T_V.KMDM=T_L.SUBJECT_ID  " +
                    		" WHERE T_V.PZ_ID=$PZ_ID AND T_V.FLH=$FLH" +
                    		" AND T_V.VSTATUS=" + EntityObject.VSTATUS_NORMAL,
                   	resultClass = Voucher.class,
                    hints = {
                    @QueryHint(name = "cache.partition", value = "function")
                            }
        ),
       @NamedNativeQuery(
                name = VoucherDAOBean.GET_VOUCHER_BY_PZID,
                query = "SELECT T_V.PZ_ID,T_V.FLH,T_V.ZY,T_V.KMDM,T_V.JJE,T_V.DJE,T_V.VSTATUS,T_L.SUBJECT_FULL_NAME AS NAME"+
                	    " FROM T_FINANCEAL_VOUCHER T_V left join T_FINANCEAL_SUBJECT_LIST T_L "+
                        "    ON T_V.KMDM=T_L.SUBJECT_ID  " +
                		" WHERE T_V.PZ_ID=$PZ_ID " +
                		" AND T_V.VSTATUS=" + EntityObject.VSTATUS_NORMAL,
               	resultClass = Voucher.class,
                hints = {
                @QueryHint(name = "cache.partition", value = "function")
                        }
        )
        }
  )

public class VoucherDAOBean extends SuperDAO implements VoucherDAO{
	public final static String GET_VOUCHER_BY_PZID = "VoucherDAOBean.getVoucherByPzId";
	public final static String GET_VOUCHER_BY_PZID_FLH = "VoucherDAOBean.getVoucherByPzIdFlh";
	public List<Voucher> getVoucherByPzId(String pzId) {
	    Map<String, Object> params = new HashMap<String, Object>(1);
        params.put("PZ_ID", pzId.trim());
        return (List<Voucher>)processNamedNativeQuery(VoucherDAOBean.GET_VOUCHER_BY_PZID,params);
    }
	public  List<Voucher> getVoucherByPzIdFlh(String pzId,String flh){
		Map<String, Object> params = new HashMap<String, Object>(2);
        String pz_id= pzId.trim();
        String flhs= flh.trim();
        params.put("PZ_ID", pz_id);
        params.put("FLH", flhs);
        return (List<Voucher>)processNamedNativeQuery(VoucherDAOBean.GET_VOUCHER_BY_PZID_FLH,params);
      }

}
